/*
 * HelpContents.java
 *
 * Created on May 30, 2008, 6:26 PM
 */

package p2p.simulator.gui;

import java.awt.Color;
import javax.swing.text.BadLocationException;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;

/**
 *
 * @author  papalukg
 */
public class HelpContents extends javax.swing.JPanel {
    
    /** Creates new form HelpContents */
    public HelpContents() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextPane2 = new javax.swing.JTextPane();
        String[] initString2 =
        {  "We implemented a simulation system in Java to evaluate the performance of various p2p protocols. " +
            "The basic architecture of the P2P simulator is based on a distributed, multi-threading," +
            " asynchronous, message passing environment. The peers exchange messages to build the" +
            " overlay network and carry out search, insert/delete as well as join/leave operations." +
            " In our simulator, each peer is a thread executable task that can run independently." +
            " Every time a message is sent, a thread is assigned to the message's destination peer" +
            " to serve that particular message. In order to avoid the thread creation overhead, thread" +
            " competition, locking problems and etc, a thread pool with tunable number of threads is maintained." +
            " Furthermore, the simulator's ability to run over a grid adds even more realism to our" +
            " experimental environment and overcomes the memory limitations.\n " +
            "The simulator has an unbiased and protocol independent mechanism to collect performance data." +
            " This mechanism is based on the observation and the filtering of special fields in the message." +
            " These fields are controlled by the simulator and are totally unaccessible from the protocol's processes." +
            " This alternative way to collect performance data, in conjunction with the realistic execution environment" +
            " yields to more accurate results."+
            "For more details visit the following address: ",
            "http://students.ceid.upatras.gr/~papalukg"
        };

        String[] initStyles2 =
        { "regular", "mail"
        };

        //JTextPane textPane = new JTextPane();
        StyledDocument doc2  = jTextPane2.getStyledDocument();
        addStylesToDocument(doc2);

        try {
            for (int i=0; i < initString2.length; i++) {
                doc2.insertString(doc2.getLength(), initString2[i],
                    doc2.getStyle(initStyles2[i]));
            }
        } catch (BadLocationException ble) {
            System.err.println("Couldn't insert initial text into text pane.");
        }

        setBorder(javax.swing.BorderFactory.createCompoundBorder(new javax.swing.border.LineBorder(javax.swing.UIManager.getDefaults().getColor("TabbedPane.borderHightlightColor"), 1, true), javax.swing.BorderFactory.createLineBorder(javax.swing.UIManager.getDefaults().getColor("TabbedPane.contentAreaColor"), 2)));
        setMinimumSize(new java.awt.Dimension(510, 464));

        jLabel2.setText("Simulator");

        jScrollPane2.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        jTextPane2.setBackground(javax.swing.UIManager.getDefaults().getColor("Panel.background"));
        jTextPane2.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jScrollPane2.setViewportView(jTextPane2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 468, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(432, 432, 432))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    
    protected void addStylesToDocument(StyledDocument doc) {
        //Initialize some styles.
        Style def = StyleContext.getDefaultStyleContext().
                        getStyle(StyleContext.DEFAULT_STYLE);

        Style regular = doc.addStyle("regular", def);
        StyleConstants.setFontFamily(def, "Dialog");
        StyleConstants.setFontSize(regular, 12);
        StyleConstants.setForeground(def, new Color(51,51,51));
        
        StyleConstants.setAlignment(regular, StyleConstants.ALIGN_JUSTIFIED);
        doc.setParagraphAttributes(0, doc.getLength(), regular, false);
        
        Style s = doc.addStyle("italic", regular);
        StyleConstants.setItalic(s, true);

        s = doc.addStyle("bold", regular);
        StyleConstants.setBold(s, true);

        s = doc.addStyle("small", regular);
        StyleConstants.setFontSize(s, 10);

        s = doc.addStyle("large", regular);
        StyleConstants.setFontSize(s, 16);
        
        s = doc.addStyle("mail", regular);
        StyleConstants.setForeground(s, Color.BLUE);
        
        /*s = doc.addStyle("icon", regular);
        StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER);
        ImageIcon pigIcon = createImageIcon("images/Pig.gif", "a cute pig");
      
        if (pigIcon != null) {
            StyleConstants.setIcon(s, pigIcon);
        }

        s = doc.addStyle("button", regular);
        StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER);
        ImageIcon soundIcon = createImageIcon("images/sound.gif",
                                              "sound icon");
        JButton button = new JButton();
        if (soundIcon != null) {
            button.setIcon(soundIcon);
        } else {
            button.setText("BEEP");
        }
        button.setCursor(Cursor.getDefaultCursor());
        button.setMargin(new Insets(0,0,0,0));
        button.setActionCommand(buttonString);
        button.addActionListener(this);
        StyleConstants.setComponent(s, button);
         */
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextPane jTextPane2;
    // End of variables declaration//GEN-END:variables
    
}
